﻿namespace CodeSHARPer.ViewModel.Dialogs
{
    using System.Reflection;
    using CodeSHARPer.ViewModel.Base;
    using System.Collections.Generic;
    using MEFedMVVM.ViewModelLocator;
    using System.ComponentModel.Composition;
    using System.Collections.ObjectModel;

    public class AboutViewModel : DialogViewModelBase
    {
        #region constructor
        public AboutViewModel() { }
        #endregion constructor

        #region properties
        public string AppTitle
        {
            get { return Assembly.GetEntryAssembly().GetName().Name; }
        }

        /// <summary>
        /// Gets the assembly copyright.
        /// </summary>
        /// <value>The assembly copyright.</value>
        public string AssemblyCopyright
        {
            get
            {
                // Get all Copyright attributes on this assembly
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

                // If there aren't any Copyright attributes, return an empty string
                if (attributes.Length == 0)
                    return string.Empty;

                // If there is a Copyright attribute, return its value
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public string AppUrl
        {
            get { return "http://CodeSHARPer.codeplex.com/"; }
        }

        public string AppUrlDisplayString
        {
            get { return "http://CodeSHARPer.codeplex.com/"; }
        }

        public string AppVersion
        {
            get { return string.Format("v{0}", Assembly.GetEntryAssembly().GetName().Version.ToString()); }
        }

        public string RunTimeVersion
        {
            get { return Assembly.GetEntryAssembly().ImageRuntimeVersion; }
        }

        ObservableCollection<string> modules;
        public ObservableCollection<string> Modules
        {
            get
            {
                if (this.modules == null)
                    GetModules();
                return modules;
            }
            set
            {
                this.modules = new ObservableCollection<string>();
                NotifyPropertyChanged(ObservableHelper.CreateArgs<AboutViewModel>(c => c.Modules));
            }
        }

        public void GetModules()
        {
            this.modules = new ObservableCollection<string>();

            this.modules.Add(typeof(AvalonDock.DockingManager).Assembly.FullName);
            this.modules.Add(typeof(Cinch.ApplicationHelper).Assembly.FullName);
            this.modules.Add(typeof(ICSharpCode.AvalonEdit.AvalonEditCommands).Assembly.FullName);
            this.modules.Add(typeof(ICSharpCode.CodeCompletion.CodeCompletionResult).Assembly.FullName);
            this.modules.Add(typeof(ICSharpCode.NRefactory.AbstractAnnotatable).Assembly.FullName);
            this.modules.Add(typeof(ICSharpCode.NRefactory.CSharp.AbiComparer).Assembly.FullName);
            this.modules.Add(typeof(ICSharpCode.NRefactory.Xml.AXmlAttribute).Assembly.FullName);
            this.modules.Add(typeof(MEFedMVVM.Common.Designer).Assembly.FullName);
            this.modules.Add(typeof(Mono.Cecil.ArrayType).Assembly.FullName);
            this.modules.Add(typeof(NLog.GlobalDiagnosticsContext).Assembly.FullName);
        }
        #endregion properties
    }
}
